package com.chainshop.product.service.impl;

import com.chainshop.product.domain.ItemCategory;
import com.chainshop.common.core.domain.pojo.ItemInformation;
import com.chainshop.product.exception.MyException;
import com.chainshop.product.mapper.ItemCategoryMapper;
import com.chainshop.product.mapper.ItemInformationMapper;
import com.chainshop.product.service.IItemCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 存储商品类别的Service业务层处理
 * 
 * @author chainshop
 * @date 2024-08-12
 */
@Service
public class ItemCategoryServiceImpl implements IItemCategoryService
{
    @Autowired
    private ItemCategoryMapper itemCategoryMapper;
    @Autowired
    private ItemInformationMapper itemInformationMapper;

    /**
     * 查询存储商品类别的
     * 
     * @param id 存储商品类别的主键
     * @return 存储商品类别的
     */
    @Override
    public ItemCategory selectItemCategoryById(Long id)
    {
        return itemCategoryMapper.selectItemCategoryById(id);
    }

    /**
     * 查询存储商品类别的列表
     * 
     * @param itemCategory 存储商品类别的
     * @return 存储商品类别的
     */
    @Override
    public List<ItemCategory> selectItemCategoryList(ItemCategory itemCategory)
    {
        return itemCategoryMapper.selectItemCategoryList(itemCategory);
    }

    /**
     * 新增存储商品类别的
     * 
     * @param itemCategory 存储商品类别的
     * @return 结果
     */
    @Override
    public int insertItemCategory(ItemCategory itemCategory)
    {
        return itemCategoryMapper.insertItemCategory(itemCategory);
    }

    /**
     * 修改存储商品类别的
     * 
     * @param itemCategory 存储商品类别的
     * @return 结果
     */
    @Override
    public int updateItemCategory(ItemCategory itemCategory)
    {
        return itemCategoryMapper.updateItemCategory(itemCategory);
    }

    /**
     * 批量删除存储商品类别的
     * 
     * @param ids 需要删除的存储商品类别的主键
     * @return 结果
     */
    @Override
    public int deleteItemCategoryByIds(Long[] ids)
    {

        return itemCategoryMapper.deleteItemCategoryByIds(ids);
    }

    /**
     * 删除存储商品类别的信息
     * 
     * @param id 存储商品类别的主键
     * @return 结果
     */
    @Override
    public int deleteItemCategoryById(Long id) throws MyException {
        List<ItemInformation> itemInformations = itemInformationMapper.selectItemInformationByCategoryId(id);
        if (itemInformations.size() > 0) {
            throw new MyException("删除失败，已有该分类商品!");
        }
        return itemCategoryMapper.deleteItemCategoryById(id);
    }
}
